package view.elaborationview;

import data.Constants;
import event.numberevent.NumberListener;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;

import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import toolkit.Language;
import view.Controller;
import view.GridView;
import view.View;

public class ElaborationView extends GridView{

	private static final long serialVersionUID = 5624411845862490191L;
	/**indica il numero di pulsanti che, nelle dimnesioni preferite, stanno su una riga nel ButtonPanel*/
	private static final int BUTTON_PER_ROW=3;
	private static final int MINIMUM_DIMENSION_X=50;
	private static final int MINIMUM_DIMENSION_Y=30;
	
	/**scrittura del nuovo segnale*/
	protected JTextField signal;
	/**scelta circa la variabile a cui assegnare il nuovo segnale*/
	protected VariableChoice variablelist;
	/**pannello che contiene tutti i pulsanti di crezione segnali*/
	private JButtonPanel buttonPanel;
	/**pannello che contiene le informazioni riguardanti le variabili della Elaboration View*/
	protected JInfoPanel infoPanel;
	/**indica il posto in cui vengono esposti i risultati*/
	private JTextArea result;
	/**indica il pannello che contiene la selezione dei 2 segnali che vengono usati per calcolare convoluzioni eccetera*/
	protected JChoicePanel variableChosenPanel;
	/**indica lo scrollpane della JTextArea*/
	private JScrollPane resultscroll;
	/**indica lo scrollpane del ButtonPanel*/
	private JScrollPane buttonscroll;
	
	
	/**indica il pulsante che assegna ad una particolare variabile specificata nella choice Variablelist un segnale*/
	protected JIDButton assignSignal;
	private JIDButton convolution;
	private JIDButton fourier;
	private JIDButton antiFourier;
	private JIDButton crossCorrelation;
	private JIDButton autoCorrelation;
	private JIDButton interSpectral;
	private JIDButton spectral;

	public ElaborationView(){
		super(Language.NAME_VIEW_ELABORATION_TITLE,NumberListener.class,ActionListener.class,ItemListener.class);
		this.buttonPanel=new JButtonPanel(BUTTON_PER_ROW);
		this.result=new JTextArea();
		this.resultscroll=new JScrollPane(this.result);
		this.buttonscroll=new JScrollPane(this.buttonPanel);
		this.variablelist=new VariableChoice();
		this.signal=new JTextField(Language.NAME_VIEW_ELABORATION_SIGNAL);
		this.infoPanel=new JInfoPanel();
		this.variableChosenPanel=new JChoicePanel();
		
		this.assignSignal=new JIDButton(Constants.ASSIGNSIGNAL,String.format(Language.NAME_VIEW_ELABORATION_ASSIGNSIGNAL,this.variablelist.getSelectedLetter()));
		this.convolution=new JIDButton(Constants.CONVOLUTION,Language.NAME_VIEW_ELABORATION_CONVOLUTION);
		this.fourier=new JIDButton(Constants.FOURIER,Language.NAME_VIEW_ELABORATION_FOURIER);
		this.antiFourier=new JIDButton(Constants.ANTIFOURIER,Language.NAME_VIEW_ELABORATION_ANTIFOURIER);
		this.crossCorrelation=new JIDButton(Constants.CROSSCORRELATION,Language.NAME_VIEW_ELABORATION_CROSSCORRELATION);
		this.autoCorrelation=new JIDButton(Constants.AUTOCORRELATION,Language.NAME_VIEW_ELABORATION_AUTOCORRELATION);
		this.interSpectral=new JIDButton(Constants.INTERSPECTRAL,Language.NAME_VIEW_ELABORATION_INTERSPECTRAL);
		this.spectral=new JIDButton(Constants.SPECTRAL,Language.NAME_VIEW_ELABORATION_SPECTRAL);

		
		this.result.setLineWrap(true);
		this.buttonPanel.add(this.assignSignal,MINIMUM_DIMENSION_X,MINIMUM_DIMENSION_Y);
		this.buttonPanel.add(this.convolution,MINIMUM_DIMENSION_X,MINIMUM_DIMENSION_Y);
		this.buttonPanel.add(this.fourier,MINIMUM_DIMENSION_X,MINIMUM_DIMENSION_Y);
		this.buttonPanel.add(this.antiFourier,MINIMUM_DIMENSION_X,MINIMUM_DIMENSION_Y);
		this.buttonPanel.add(this.crossCorrelation,MINIMUM_DIMENSION_X,MINIMUM_DIMENSION_Y);
		this.buttonPanel.add(this.autoCorrelation,MINIMUM_DIMENSION_X,MINIMUM_DIMENSION_Y);
		this.buttonPanel.add(this.interSpectral,MINIMUM_DIMENSION_X,MINIMUM_DIMENSION_Y);
		this.buttonPanel.add(this.spectral,MINIMUM_DIMENSION_X,MINIMUM_DIMENSION_Y);
		
		this.add(this.variablelist,0,0,1,1,1./12,1./4,GridBagConstraints.HORIZONTAL);
		this.add(this.signal,1,0,1,1,7./12,1./4);
		this.add(this.resultscroll,1,1,1,1,7./12,1./4,GridBagConstraints.BOTH);
		this.add(this.infoPanel,2,0,1,4,1./3,1);
		this.add(this.variableChosenPanel,0,2,2,1,2./3,1./12);
		this.add(this.buttonscroll,0,3,2,1,2./3,5./12,GridBagConstraints.BOTH);
		this.infoPanel.setBackground(Color.red);
		this.buttonPanel.setBackground(Color.blue);
	}
	
	@Override
	public void showview() {
		// TODO Auto-generated method stub
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public void addListeners(Controller<? extends View> controller) {
		this.variablelist.addNumberListener((NumberListener<Integer>) controller);
		this.variablelist.addItemListener((ItemListener)controller);
		this.convolution.addActionListener((ActionListener)controller);
		this.fourier.addActionListener((ActionListener)controller);
		this.antiFourier.addActionListener((ActionListener)controller);
		this.assignSignal.addActionListener((ActionListener)controller);
		this.crossCorrelation.addActionListener((ActionListener)controller);
		this.autoCorrelation.addActionListener((ActionListener)controller);
		this.spectral.addActionListener((ActionListener)controller);
		this.interSpectral.addActionListener((ActionListener)controller);
	}


}
